package com.example.phone;

import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/verifyPhone")
public class VerifyPhoneServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String userCode = request.getParameter("code");
        String storedCode = (String) request.getSession().getAttribute("phone_code");

        if (userCode != null && userCode.equals(storedCode)) {
            // 验证成功
            response.getWriter().write("{\"success\":true}");
        } else {
            // 验证失败
            response.getWriter().write("{\"success\":false,\"message\":\"验证码错误\"}");
        }
    }
}
